package com.niiwoo.civet.trade.service.local.loan.creditaduit;

import java.util.concurrent.CompletableFuture;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.civet.trade.enums.ProjectTypeEnum;
import com.niiwoo.civet.user.service.TianchengDataDubboService;
import com.niiwoo.civet.user.service.UserForbidDubboService;
import com.niiwoo.tripod.tiancheng.component.TianchengAgainstFakeV2Service;
import com.niiwoo.tripod.tiancheng.enums.FunctionCodeEnum;
import com.niiwoo.tripod.tiancheng.request.afp.CreditAduitAgainLoanRequest;
import com.niiwoo.tripod.tiancheng.request.afp.CreditAduitFirstLoanRequest;
import com.niiwoo.tripod.tiancheng.request.afp.KaDaiRepairServiceRequest;
import com.niiwoo.tripod.tiancheng.response.common.AgainstFakeV2Response;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description:社保贷
 * @Author:zhoulinquan
 * @Date:2017/4/19
 */
@Slf4j
@Service
public class SocailSecurityLoanCreditAduitService extends AbstractCreditAuditService {
	@Autowired
    private TianchengAgainstFakeV2Service tianchengAgainstFakeV2Service;
	
	@Reference(version = "1.0.0")
	private TianchengDataDubboService tianchengDataDubboService;
	@Reference(version = "1.0.0")
	private UserForbidDubboService userForbidDubboService;

	@Override
	public AgainstFakeV2Response firstLoan(CreditAduitFirstLoanRequest request) throws Exception {
        log.info("标的ID={},发起标准化社保贷首借用户信审请求,请求参数={}.", request.getProject_id(), JSON.toJSONString(request));
        CompletableFuture<AgainstFakeV2Response> completableFuture = tianchengAgainstFakeV2Service.qualificationFirstLoanCreditAduit(request);
        
        AgainstFakeV2Response againstFakeV2Response = completableFuture.get();
        log.info("标的ID={},发起标准化社保贷首借用户信审请求,响应结果={}.", request.getProject_id(), JSON.toJSONString(againstFakeV2Response));
        
        return againstFakeV2Response;
	}

	@Override
	public AgainstFakeV2Response againLoan(CreditAduitAgainLoanRequest request) throws Exception {
        log.info("标的ID={},发起标准化社保贷 复借用户信审请求,请求参数={}.", request.getProject_id(), JSON.toJSONString(request));
        CompletableFuture<AgainstFakeV2Response> completableFuture = tianchengAgainstFakeV2Service.qualificationAgainLoanCreditAduit(request);
        
    	AgainstFakeV2Response againstFakeV2Response = completableFuture.get();
        log.info("标的ID={},发起标准化社保贷复借用户信审请求,响应结果={}.", request.getProject_id(), JSON.toJSONString(againstFakeV2Response));
        
        return againstFakeV2Response;
	}

	@Override
	public ProjectTypeEnum getProjectType() {
		return ProjectTypeEnum.SOCIAL_SECURITY_LOAN;
	}
	
	@Override
	public FunctionCodeEnum getFunctionCode() {
		return isAgainLoan ? FunctionCodeEnum.LIBRA_CREDIT_QULIFICATION_AGAIN : FunctionCodeEnum.LIBRA_CREDIT_QULIFICATION_FIRST;
	}
	
	@Override
	public AgainstFakeV2Response repair(KaDaiRepairServiceRequest request) throws Exception {
		log.info("标的ID={},发起标准化社保贷复借用户信审请求,请求参数={}.", request);
        CompletableFuture<AgainstFakeV2Response> completableFuture = tianchengAgainstFakeV2Service.repairService(request);
        
    	AgainstFakeV2Response againstFakeV2Response = completableFuture.get();
        log.info("标的ID={},发起标准化社保贷复借用户信审请求,响应结果={}.", againstFakeV2Response);
        
        return againstFakeV2Response;
	}
	
	@Override
	public TianchengDataDubboService getTianchengDataDubboService() {
		return tianchengDataDubboService;
	}

	@Override
	public UserForbidDubboService getUserForbidDubboService() {
		return userForbidDubboService;
	}
}
